/*
 * @Author: leemr lscmr@qq.com
 * @Date: 2023-12-21 09:56:05
 * @LastEditors: leemr lscmr@qq.com
 * @LastEditTime: 2023-12-21 10:30:07
 * @FilePath: \futures-bill\src\controller\log.ts
 * @Description:
 *
 */
import UAParser from 'ua-parser-js'
import { getBrowserId } from '~/apis'
import { ua } from '~/utils/util'

export const userAg = UAParser(ua)
const data = {
  webType: userAg.browser.name,
  userAgent: userAg.ua,
  webVersion: userAg.browser.version,
  cookieEnabled: navigator.cookieEnabled,
  platform: navigator.platform,
  height: window.screen.height,
  width: window.screen.width,
  colorDepth: window.screen.colorDepth,
  os: userAg.os.name,
  Osystem: userAg.os.version,
}

const LocalstorageKey = 'browserId_HAQH_app'

export async function useLog() {
  let BrowserId = localStorage.getItem(LocalstorageKey)
  if (!BrowserId) {
    const [_, res] = await getBrowserId(data)
    BrowserId = res.BrowserId
    BrowserId
    = BrowserId === undefined ? `${new Date().getTime()}_` + `error` : BrowserId
    localStorage.setItem(LocalstorageKey, BrowserId)
  }
  return BrowserId
}
